$(function(){
	var ind = 1;
	var sidebarUlLeft = $(".sidebarUlLeft").find(".navlistchage");
	sidebarUlLeft.click(function(){
	 	updataImg($(this));
	})
	
	function updataImg(_this){
		var _index = _this.index()+1;
		ind = _index;
		_this.removeClass("colorB");
		_this.children().removeClass("hreadChages");
		_this.siblings(".bhover").addClass("colorB");
		$(".contextRight"+_index).css("display","block").siblings(".contextMargin").css("display","none");
		_this.addClass("hreadChage").siblings().removeClass("hreadChage");
		
		var navImg = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon_hover"+_index+".png" : "Application/Home/Static/bt/img/bang_"+_index+".png";
		var navImg1 = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon1.png" : "Application/Home/Static/bt/img/bang1.png";
		var navImg2 = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon2.png" : "Application/Home/Static/bt/img/bang2.png";
		var navImg3 = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon3.png" : "Application/Home/Static/bt/img/bang3.png";
		if(_index == 1){
			_this.children().children().attr("src",navImg);
			$(".class2").children().children().attr("src",navImg2);
			$(".class3").children().children().attr("src",navImg3);
			$(".leftArrow").css("top","15%");
			
		}else if(_index == 2){
			_this.children().children().attr("src",navImg);
			$(".class1").children().children().attr("src",navImg1);
			$(".class3").children().children().attr("src",navImg3);
			$(".leftArrow").css("top","48%");
			redirectPage();
			
		}else if(_index == 3){
			_this.children().children().attr("src",navImg);
			$(".class1").children().children().attr("src",navImg1);
			$(".class2").children().children().attr("src",navImg2);
			$(".leftArrow").css("top","83%");
		}
	}
	
	sidebarUlLeft.hover(function(){
		var _index = $(this).index()+1;
		sidebarUlLeftIn(_index,$(this));
	},function(){
		var _index = $(this).index()+1;
		sidebarUlLeftOut(_index,$(this));
	})
	
	function sidebarUlLeftIn(_index,_this){
		if(_this.hasClass("hreadChage")) return
		
		$(".sidebar-collapse").hasClass("chageMin") ? _this.children().children().attr("src","Application/Home/Static/bt/img/icon_hover"+_index+".png") : _this.children().children().attr("src","Application/Home/Static/bt/img/bang_"+_index+".png");
		
		_this.children().addClass("colorD hreadChages");
	}
	function sidebarUlLeftOut(_index,_this){
		if(_this.hasClass("hreadChage")) return
		
		$(".sidebar-collapse").hasClass("chageMin") ? _this.children().children().attr("src","Application/Home/Static/bt/img/icon"+_index+".png") : _this.children().children().attr("src","Application/Home/Static/bt/img/bang"+_index+".png");
		
		_this.children().removeClass("colorD hreadChages");
	}
	/*输入框的变色*/
	$("input,textarea,select").focus(function(){
		$(this).css("border","1px #354052 solid");
	})
	$("input,textarea,select").blur(function(){
		$(this).css("border","0px #354052 solid");
	})
	
	$(".listing").focus(function(){
		$(this).parent().siblings(".listingmsg").css("display","block")
	})
	$(".listing").blur(function(){
		$(this).parent().siblings(".listingmsg").css("display","none")
	})
	
	
	/*模态弹出框*/
	$(".resultBtn").click(function(){
		$(".modalAlert").show();
	});
	
	$(".close").click(function(){
		$(".modal").hide();
	})
	
	
	/*关键词分析自动生成数据*/
	function updataH(){
		var tab1Height = $(".btnmore").height();
		var keyH = $(".bgcolorMidK").height();
		if(tab1Height>=900){
			$(".bgcolorMid").css("height",tab1Height-170);
		}
	}
	updataH();			
	$(".addBtn").click(function(){
		/*每一个table的数量不能超过40包括（40），超过40就自动生成一个table，以此类推*/
		var trLength = $(".ct_tableContainer:last-child").children("table").children("tbody").find("tr").length;
	
		if(trLength>120){
			/*整个table的数量*/
			var ct_length = $(".ct_tableContainer").length+1;
			var _html = " ";
			if(ct_length % 3 == 2){
				_html +='<div class="ct_tableContainer ct_table_padding">';
			}else{
				_html +='<div class="ct_tableContainer">';
			}
			_html +='<table class="ct_table">';
			_html +='<thead>';
			_html +='<tr class="tableStyle">';
			_html +='<th>aa</th><th>1</th><th>1%</th>';
			_html +='</tr>';
			_html +='</thead>';
			_html +='<tbody>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='</tbody>';
			_html +='</table>';
			_html +='</div>';
			
			$(".ct_context").append(_html);
		}
		updataH();
	})
	
	/*清空文本域的值*/
	$(".clearBtn").on("click",function(){
		$(".clearText").val(" ");
		$(".clearText").focus();
	})
	
	/*左边导航栏*/
	$(".sidebar-collapse").on("click",function(){
		if($(this).hasClass("chageMin")){
			$(this).removeClass("chageMin");
			$(".sidebar-toggle .ace-icon img").attr("src","Application/Home/Static/bt/img/lefts.png")
			$(".sidebarUlLeft li a img").css({"width":"91px","height":"90px"});
			$(".updataImg img").css({"width":"73px","height":"67px"});
			var imgout1 = (ind == 1) ? "Application/Home/Static/bt/img/bang_1.png" : "Application/Home/Static/bt/img/bang1.png";
			var imgout2 = (ind == 2) ? "Application/Home/Static/bt/img/bang_2.png" : "Application/Home/Static/bt/img/bang2.png";
			$(".class1").children().children().attr("src",imgout1);
			$(".class2").children().children().attr("src",imgout2);
			$(".class3").children().children().attr("src","Application/Home/Static/bt/img/bang3.png");
		}else{
			$(this).addClass("chageMin");
			$(".sidebar-toggle .ace-icon img").attr("src","Application/Home/Static/bt/img/rights.png")
			$(".sidebarUlLeft li a img").css({"width":"32px","height":"32px"});
			$(".updataImg img").css({"width":"43px","height":"39px"});
			var imgIn1 = (ind == 1) ? "Application/Home/Static/bt/img/icon_hover1.png" : "Application/Home/Static/bt/img/icon1.png";
			var imgIn2 = (ind == 2) ? "Application/Home/Static/bt/img/icon_hover2.png" : "Application/Home/Static/bt/img/icon2.png";
			$(".class1").children().children().attr("src",imgIn1);
			$(".class2").children().children().attr("src",imgIn2);
			$(".class3").children().children().attr("src","Application/Home/Static/bt/img/icon3.png");
		}
		
	})
	
	
	/*下拉框的选择功能*/
	var menu = $(".delayed").find("li");
	menu.on("click",function(){
		$(".delayedInput").val($(this).children().html())
	})
	
	var proportion = $(".proportion").find("li");
	proportion.on("click",function(){
		$(this).parent().parent().siblings("input").val($(this).children().html())
	})
	
	var downBtn = $(".downBtn").find("li");
	downBtn.on("click",function(){
		$(this).parent().parent().siblings("input").val($(this).children().html())
	})
	/*检测分辨率是否是小屏幕*/
	function redirectPage(){
		var screenWh = screen.width;
		if(screenWh <= 1366){
			//var navH = $(".navbar").css("height")+30;
			$('body,html').animate({ scrollTop: 200 }, 800);
		}
	}
	
	
	$(".checkGroup").on("click",function(){
		if($(this).children("i").hasClass("okBtn")){
			$(this).children("i").removeClass("okBtn glyphicon glyphicon-ok");
		}else{
			$(this).children("i").addClass("okBtn glyphicon glyphicon-ok");
		}
	})
	
	
	$(".radioContainer .radioGroup").on("click",function(){
		
		if($(this).children().children("i").hasClass("logo")){
			return;
		}
		if(!$(this).children().children("i").hasClass("radioLogo")){
			$(this).children().children("i").addClass("radioLogo logo");
			$(this).siblings().children().children().removeClass("radioLogo logo");
		}
	})
	
	
	/*提示框的效果*/
	$(".tooltipBtn").hover(function(){
		$(this).siblings(".tool").css("display","block");
	},function(){
		$(this).siblings(".tool").css("display","none");
	})
	
	function newDataTime(){
		var date = new Date();
		var Time = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
			Time +=" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
			$(".Time").html("中国银行"+Time);
	}
	newDataTime();
/*	$("#txtKeywordsMaxNum").on("keyup",function(){
		var maxNum = $(this).val();
		var re = new RegExp(/[^\d]/);
		console.log(re.test(maxNum))
		maxNum.replace(re,'');
	})*/
	
	/*table切换功能*/
	var shoptable = $(".shopTable .shopNav").find("li");
	shoptable.on("click",function(){
		var _index = $(this).index()+1;
		$("div[class*=shoptable]").hide();
		$(".shoptable"+_index).show();
		$(this).addClass("active").siblings().removeClass("active");
	})
	
	var authorizetable = $(".authorizeTable .authorize-tabs").find("li");
	authorizetable.on("click",function(){
		var _index = $(this).index()+1;
		$("div[class*=shopAuthorize]").hide();
		$(".shopAuthorize"+_index).show();
		$(this).addClass("active").siblings().removeClass("active");
	})
	
	
	$(".setBtnClick").hover(function(){
		if(!$(this).hasClass("setbtn")){
			$(this).children("b").removeClass("fa-angle-down").addClass("fa-angle-up");
			$(this).addClass("setbtn");
			$(".setItme").fadeIn(200);
		}else{
			$(this).children("b").removeClass("fa-angle-up").addClass("fa-angle-down");
			$(this).removeClass("setbtn")
			$(".setItme").fadeOut(200);
		}
	})
	
	var setItme = $(".setItme ul").find("li");
	setItme.hover(function(){
		$(this).css({"background":"#00c18a","color":"#ffffff"});
	},function(){
		$(this).css({"background":"#FFFFFF","color":"#9ba7b9"});
	})
	
	/*商品调价用户登录modal窗体*/
	$(".modalClick").on("click",function(){
		$("#shopModal").remove();
		var _html = "";
		_html +='<div class="modal fade" role="dialog" id="shopModal" aria-labelledby="gridSystemModalLabel">';
		_html +='<div class="modal-dialog" role="document">';
		_html +='<div class="modal-content">';
		_html +='<div class="modal-header">';
		_html +='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>';
		_html +='<h4 class="modal-title" id="myModalLabel">用户登录</h4>';
		_html +='</div>';
		_html +='<div class="modal-body">';
		_html +='<div class="modalMagrin">';
		_html +='<div class="modalMsg">此功能免费，但需与亚马逊数据同步，为了您的信息安全，请登录后使用</div>';
		_html +='<div class="modalDody">';
		_html +='<div class="userContainer ">';
		_html +='<input class="userStyle modalW userBorder" type="text" placeholder="请输入邮箱"/>';
		_html +='<div class="modalLogo"><img src="Application/Home/Static/bt/img/user/user.png"/></div>';
		_html +='</div>';
		
		_html +='<div class="userContainer">';
		_html +='<input class="userStyle modalW userBorder" type="text" placeholder="请输入密码"/>';
		_html +='<div class="modalLogo modalPosition"><img src="Application/Home/Static/bt/img/user/userlogo.png"/></div>';
		_html +='</div>';
		
		_html +='<div class="userContainer ">';
		_html +='<div class="userLogoBtn modalW" style="color:#FFFFFF">登录</div>';
		_html +='</div>';
		
		_html +='<div class="userContainer clearfix">';
		_html +='<div class="clearBtn size14 color9 ForgetPwd modalLeft">忘记密码？</div>';
		_html +='<div class="modalStyle modalColor size14">';
		_html +='<span style="color:#666666">没有账户？</span>';
		_html +='<span class="modalColor" style="cursor: pointer;">立即注册</span>';
		_html +='</div>';
		
		_html +='</div></div></div></div></div></div></div>';
		$("body").append(_html);
	})
/*	$('#myModal').on('shown.bs.modal', function() {
		$('#myInput').focus()
	})*/
	
	$(".readjustClick").on("click",function(){
		$(".readjustModal").remove();
		var _html = '';
		_html +='<div class="modal fade" id="readjustModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">';
		_html +='<div class="modal-dialog" role="document">';
		_html +='<div class="modal-content">';
		_html +='<div class="modal-header">';
		_html +='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
		_html +='<h4 class="modal-title" id="myModalLabel">FBM库存批量调整</h4>';
		_html +='</div>';
		
		_html +='<div class="modal-body" style="padding: 30px 0 !important;">';
		_html +='<form class="form-horizontal" role="form" style="margin-left: 30px;">';
		_html +='<div class="form-group formmarginTop">';
		_html +='<label class="col-sm-2 col-xs-12 control-label no-padding-right labeichage shopright0">可售 <=</label>';
		_html +='<div class="col-sm-6 col-xs-10">';
		_html +='<input type="text" id="inputStyle" class="col-xs-10 col-sm-12 color3 tooltipBtn keyInput">';
		_html +='</div></div>';
		_html +='<div class="form-group formmarginTop">';
		_html +='<label class="col-sm-2 col-xs-12 control-label no-padding-right labeichage shopright0">全部调整为：</label>';
		_html +='<div class="col-sm-6 col-xs-10"><input type="text" id="inputStyle" class="col-xs-10 col-sm-12 color3 tooltipBtn keyInput"></div>';
		_html +='<div class="col-sm-4">';
		_html +='<div class="checkbox size14 ">';
		_html +='<div class="checkGroup position size14 ckBtn" onclick="ckBtn()">';
		_html +='<span class="color6 labeiLeft20">累加现在的可售数</span><i class="checkLogo"></i>';
		_html +='</div></div>';
		_html +='</div>';
		_html +='</div>';
		_html +='</form>';
		_html +='</div>';
		
		_html +='<div class="modal-footer">';
		_html +='<div class="updateBtnright modalFloat submitBtn" data-dismiss="modal">确定</div>';
		_html +='</div>';
		_html +='</div></div></div>';
		
		$("body").append(_html);
	})
	
	
	/*账户设置*/
	$(".userManageClick").on("click",function(){
		var imgarry = ["Application/Home/Static/bt/img/bang1.png","Application/Home/Static/bt/img/bang2.png","Application/Home/Static/bt/img/bang3.png"];
		var _index = $(this).attr("data-index");
		$(".contextRight"+_index).show().siblings("div[class*='contextRight']").hide();
		var side = $(".sidebarUlLeft").find("li");
		var sum = 0;
		for(var i=0,len=side.length;i<len;i++){
			sum = i+1;
			side.addClass("colorB").removeClass("hreadChage");
			$(".class"+sum).children().children().attr("src",imgarry[i]);
		}
	})
	
	/*授权table切换复选框效果*/
	$(".authorizeBtnClick").on("click",function(){
		var _html = "";
		var name = $(this).children("span").text();
		var authorizeIndex =$(".authorizeTable").children().children(".active").attr("data-cty");
		
		var _index = $(this).attr("data-tab");
		if(!$(this).children("i").hasClass("okBtn")){
			$(".removeIndex"+_index).remove();
			return;
		}
		_html +='<div class="col-xs-12 shopleft0 shopright0 marginBottom20 removeInputDiv removeIndex'+_index+'">';
		_html +='<label class="col-xs-2 shopleft0 shopright0 labeiTop6">店铺名称：</label>';
		_html +='<input id="inputStyle" class="col-xs-10" type="text" placeholder="请输入'+name+'店铺名称" />';
		_html +='</div>';
		
		$(".shopAuthorize"+authorizeIndex).append(_html);
	})
	
	$(".timeInputxs").focus(function(){
		$(".borderLeft").css("border-left","1px #000000 solid")
	});
	$(".timeInputxs").blur(function(){
		$(".borderLeft").css("border-left","0px #000000 solid")
	});
	
	/*商品调价保存按钮*/
	$(".savaBtnClick").on("keyup",function(){
		var value = $(this).val().replace(/[^\d+.]/g,'');
		$(this).val(value);
		$(this).siblings(".savalogo").show();
	})
	
	/*用户注册导航栏功能*/
	var logoNav = $(".logoNavRight").find("a");
	logoNav.hover(function(){
		$(this).addClass("active");
	},function(){
		$(this).removeClass("active");
	});
	
	/*未登录用户弹出的media  Input边框*/
	$(document).on("focus","input[class~=userBorder]",function(){
		$(this).css("border","1px #354052 solid");
	})
	$(document).on("blur","input[class~=userBorder]",function(){
		$(this).css("border","0px #354052 solid");
	})
	
	/*商品调价下拉列表*/
	var menuClick = $(".inputContai").find(".menuClick");
	menuClick.on("click",function(){
		if($(".inputMenu").hasClass("open")){
			$(this).children().removeClass("open");
			$(this).children().children("button").attr("aria-expanded","true");
		}else{
			$(this).children().addClass("open");
			$(this).children().children("button").attr("aria-expanded","true");
		}
	})


});
